package org.jeecg.modules.demo.zyExam.zypaperperson.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.jeecg.modules.demo.zyExam.zypaperperson.entity.ZyPaperPerson;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

/**
 * @Description: 试卷和人中间表
 * @Author: jeecg-boot
 * @Date:   2024-01-11
 * @Version: V1.0
 */
@Repository
public interface ZyPaperPersonMapper extends BaseMapper<ZyPaperPerson> {

    @Select({
            "SELECT",
            "name,",
            "MAX(is_pass) AS is_pass,",
            "SUM(score) AS score,",
            "MAX(is_exam) AS is_exam,",
            "SUM(total_score) AS total_score",
            "FROM zy_paper_person",
            "WHERE paper_id = #{paperId}",
            "GROUP BY name"
    })
    List<Map<String, Object>> queryMaxScoreByPaperCode(String paperId);

    @Select("select id from sys_user where realname=#{realname}")
    String getByName(String realname);


    @Select("SELECT * FROM zy_paper_person \n" +
            "WHERE paper_id = #{id} \n" +
            "  AND name = #{name}")
    ZyPaperPerson editByNameAndPaperId(@RequestParam(name = "id") String id,@RequestParam(name = "name") String name);

    @Delete("DELETE FROM zy_paper_person WHERE paper_id = #{id}")
    void deleteByPaperCode(String id);
}
